package com.yyfax.ph.home.recommendloan.otherinfo;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.IView;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yyfax.infrastructure.mvp.PresenterFactory;
import com.yyfax.infrastructure.statistics.StatService;
import com.yyfax.ph.StatIDSet;
import com.yyfax.ph.base.YJPH;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * P: 其他资料
 * Created by ying_he on 2017/11/9.<br>
 * Copyright  2017 www.yylending.com. All Rights Reserved.<br><br>
 */

public class OtherInfoPresenter extends Presenter<OtherInfoModel, OtherInfoPresenter.View>{
	private static final String TAG = OtherInfoPresenter.class.getSimpleName();

	public static class Generator implements PresenterFactory<OtherInfoPresenter> {
		@Override
		public OtherInfoPresenter create() {
			return new OtherInfoPresenter();
		}
	}

	public interface View extends IView{
		void uploadOtherInfoSuccess(String msg);
		void uploadOtherInfoFailed(String msg);

	}

	private View mView;

	@Override
	public void attach(View view) {
		mView = view;
		mModel = new OtherInfoModel();
		EventAgent.register(this);
	}

	@Override
	public void detach() {
		mView = null;
		mModel = null;
		EventAgent.unregister(this);
	}

	public void uploadOtherInfo(OtherInfoModel.OtherInfoParams otherInfoParams){
		execute(otherInfoParams, FUNCTIONAL_CODE, true);
	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void uploadOtherInfoResult(OtherInfoModel.UploadOtherInfoResult result){
		StatService.onEventFirstKeyAttribute(YJPH.getInstance(), StatIDSet.EVENT_ID_B006, result.getStatus());
		if (isResponseSuccess(result)) {
			mView.uploadOtherInfoSuccess(result.getMsg());
		}else {
			mView.uploadOtherInfoFailed(result.getMsg());
		}
	}
}
